// This file replicates Tables A5, A7, A8, A6, and Figure C1


clear
// Download the Senate Committee Assignments data
use SenateChamberSeniorityAtAssignment.dta

*************************************************************************************
** Tables A5 and A7 data **
*************************************************************************************


* Agriculture Committee
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Agriculture, Nutrition, and Forestry"
matrix stats_R_Agriculture = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_Agriculture

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Agriculture, Nutrition, and Forestry"
matrix stats_D_Agriculture = (r(mean), r(sd), r(N))
matrix list stats_D_Agriculture

matrix Stats_Agriculture = stats_R_Agriculture, stats_D_Agriculture
matrix Stats_Agriculture = Stats_Agriculture, (stats_R_Agriculture[1,1] - stats_D_Agriculture[1,1])
matrix Stats_Agriculture = Stats_Agriculture, (Stats_Agriculture[1,8]/sqrt(Stats_Agriculture[1,2]^2/Stats_Agriculture[1,3]+ Stats_Agriculture[1,6]^2/Stats_Agriculture[1,7]))
matrix Stats_Agriculture = Stats_Agriculture, (Stats_Agriculture[1,2] - Stats_Agriculture[1,6])
matrix list Stats_Agriculture


* Appropriations Committee
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Appropriations"
matrix stats_R_Appropriations = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_Appropriations

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Appropriations"
matrix stats_D_Appropriations = (r(mean), r(sd), r(N))
matrix list stats_D_Appropriations

matrix Stats_Appropriations = stats_R_Appropriations, stats_D_Appropriations
matrix Stats_Appropriations = Stats_Appropriations, (stats_R_Appropriations[1,1] - stats_D_Appropriations[1,1])
matrix Stats_Appropriations = Stats_Appropriations, (Stats_Appropriations[1,8]/sqrt(Stats_Appropriations[1,2]^2/Stats_Appropriations[1,3]+ Stats_Appropriations[1,6]^2/Stats_Appropriations[1,7]))
matrix Stats_Appropriations= Stats_Appropriations, (Stats_Appropriations[1,2] - Stats_Appropriations[1,6])
matrix list Stats_Appropriations



* Armed Services
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Armed Services"
matrix stats_R_armedservices = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_armedservices

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Armed Services"
matrix stats_D_armedservices = (r(mean), r(sd), r(N))
matrix list stats_D_armedservices

matrix Stats_armedservices = stats_R_armedservices, stats_D_armedservices
matrix Stats_armedservices = Stats_armedservices, (stats_R_armedservices[1,1] - stats_D_armedservices[1,1])
matrix Stats_armedservices = Stats_armedservices, (Stats_armedservices[1,8]/sqrt(Stats_armedservices[1,2]^2/Stats_armedservices[1,3]+ Stats_armedservices[1,6]^2/Stats_armedservices[1,7]))
matrix Stats_armedservices= Stats_armedservices, (Stats_armedservices[1,2] - Stats_armedservices[1,6])
matrix list Stats_armedservices



* Banking, Housing, and Urban Affairs 
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Banking, Housing, and Urban Affairs"
matrix stats_R_banking = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_banking

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Banking, Housing, and Urban Affairs"
matrix stats_D_banking = (r(mean), r(sd), r(N))
matrix list stats_D_banking


matrix Stats_banking = stats_R_banking, stats_D_banking
matrix Stats_banking = Stats_banking, (stats_R_banking[1,1] - stats_D_banking[1,1])
matrix Stats_banking = Stats_banking, (Stats_banking[1,8]/sqrt(Stats_banking[1,2]^2/Stats_banking[1,3]+ Stats_banking[1,6]^2/Stats_banking[1,7]))
matrix Stats_banking= Stats_banking, (Stats_banking[1,2] - Stats_banking[1,6])
matrix list Stats_banking



* Budget
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Budget"
matrix stats_R_budget = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_budget

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Budget"
matrix stats_D_budget = (r(mean), r(sd), r(N))
matrix list stats_D_budget

matrix Stats_budget = stats_R_budget, stats_D_budget
matrix Stats_budget = Stats_budget, (stats_R_budget[1,1] - stats_D_budget[1,1])
matrix Stats_budget = Stats_budget, (Stats_budget[1,8]/sqrt(Stats_budget[1,2]^2/Stats_budget[1,3]+ Stats_budget[1,6]^2/Stats_budget[1,7]))
matrix Stats_budget= Stats_budget, (Stats_budget[1,2] - Stats_budget[1,6])
matrix list Stats_budget




* Commerce, Science, and Transportation
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Commerce, Science, and Transportation"
matrix stats_R_commerce = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_commerce

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Commerce, Science, and Transportation"
matrix stats_D_commerce = (r(mean), r(sd), r(N))
matrix list stats_D_commerce

matrix Stats_commerce = stats_R_commerce, stats_D_commerce
matrix Stats_commerce = Stats_commerce, (stats_R_commerce[1,1] - stats_D_commerce[1,1])
matrix Stats_commerce = Stats_commerce, (Stats_commerce[1,8]/sqrt(Stats_commerce[1,2]^2/Stats_commerce[1,3]+ Stats_commerce[1,6]^2/Stats_commerce[1,7]))
matrix Stats_commerce= Stats_commerce, (Stats_commerce[1,2] - Stats_commerce[1,6])
matrix list Stats_commerce



* Energy and Natural Resources
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Energy and Natural Resources"
matrix stats_R_energy = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_energy

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Energy and Natural Resources"
matrix stats_D_energy = (r(mean), r(sd), r(N))
matrix list stats_D_energy

matrix Stats_energy = stats_R_energy, stats_D_energy
matrix Stats_energy = Stats_energy, (stats_R_energy[1,1] - stats_D_energy[1,1])
matrix Stats_energy = Stats_energy, (Stats_energy[1,8]/sqrt(Stats_energy[1,2]^2/Stats_energy[1,3]+ Stats_energy[1,6]^2/Stats_energy[1,7]))
matrix Stats_energy= Stats_energy, (Stats_energy[1,2] - Stats_energy[1,6])
matrix list Stats_energy



* Environment and Public Works
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Environment and Public Works"
matrix stats_R_environment = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_environment

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Environment and Public Works"
matrix stats_D_environment = (r(mean), r(sd), r(N))
matrix list stats_D_environment

matrix Stats_environment = stats_R_environment, stats_D_environment
matrix Stats_environment = Stats_environment, (stats_R_environment[1,1] - stats_D_environment[1,1])
matrix Stats_environment = Stats_environment, (Stats_environment[1,8]/sqrt(Stats_environment[1,2]^2/Stats_environment[1,3]+ Stats_environment[1,6]^2/Stats_environment[1,7]))
matrix Stats_environment= Stats_environment, (Stats_environment[1,2] - Stats_environment[1,6])
matrix list Stats_environment



* Finance
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Finance"
matrix stats_R_Finance = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_Finance

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Finance"
matrix stats_D_Finance = (r(mean), r(sd), r(N))
matrix list stats_D_Finance

matrix Stats_Finance = stats_R_Finance, stats_D_Finance
matrix Stats_Finance = Stats_Finance, (stats_R_Finance[1,1] - stats_D_Finance[1,1])
matrix Stats_Finance = Stats_Finance, (Stats_Finance[1,8]/sqrt(Stats_Finance[1,2]^2/Stats_Finance[1,3]+ Stats_Finance[1,6]^2/Stats_Finance[1,7]))
matrix Stats_Finance= Stats_Finance, (Stats_Finance[1,2] - Stats_Finance[1,6])
matrix list Stats_Finance



* Foreign Relations
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Foreign Relations"
matrix stats_R_ForeignRelations = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_ForeignRelations

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Foreign Relations"
matrix stats_D_ForeignRelations = (r(mean), r(sd), r(N))
matrix list stats_D_ForeignRelations

matrix Stats_ForeignRelations = stats_R_ForeignRelations, stats_D_ForeignRelations
matrix Stats_ForeignRelations = Stats_ForeignRelations, (stats_R_ForeignRelations[1,1] - stats_D_ForeignRelations[1,1])
matrix Stats_ForeignRelations = Stats_ForeignRelations, (Stats_ForeignRelations[1,8]/sqrt(Stats_ForeignRelations[1,2]^2/Stats_ForeignRelations[1,3]+ Stats_ForeignRelations[1,6]^2/Stats_ForeignRelations[1,7]))
matrix Stats_ForeignRelations= Stats_ForeignRelations, (Stats_ForeignRelations[1,2] - Stats_ForeignRelations[1,6])
matrix list Stats_ForeignRelations



* Governmental Affairs
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Governmental Affairs"
matrix stats_R_GovernmentalAffairs = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_GovernmentalAffairs

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Governmental Affairs"
matrix stats_D_GovernmentalAffairs = (r(mean), r(sd), r(N))
matrix list stats_D_GovernmentalAffairs

matrix Stats_GovernmentalAffairs = stats_R_GovernmentalAffairs, stats_D_GovernmentalAffairs
matrix Stats_GovernmentalAffairs = Stats_GovernmentalAffairs, (stats_R_GovernmentalAffairs[1,1] - stats_D_GovernmentalAffairs[1,1])
matrix Stats_GovernmentalAffairs = Stats_GovernmentalAffairs, (Stats_GovernmentalAffairs[1,8]/sqrt(Stats_GovernmentalAffairs[1,2]^2/Stats_GovernmentalAffairs[1,3]+ Stats_GovernmentalAffairs[1,6]^2/Stats_GovernmentalAffairs[1,7]))
matrix Stats_GovernmentalAffairs= Stats_GovernmentalAffairs, (Stats_GovernmentalAffairs[1,2] - Stats_GovernmentalAffairs[1,6])
matrix list Stats_GovernmentalAffairs


* Health, Education, Labor, and Pensions
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Health, Education, Labor, and Pensions"
matrix stats_R_health = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_health

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Health, Education, Labor, and Pensions"
matrix stats_D_health = (r(mean), r(sd), r(N))
matrix list stats_D_health

matrix Stats_health = stats_R_health, stats_D_health
matrix Stats_health = Stats_health, (stats_R_health[1,1] - stats_D_health[1,1])
matrix Stats_health = Stats_health, (Stats_health[1,8]/sqrt(Stats_health[1,2]^2/Stats_health[1,3]+ Stats_health[1,6]^2/Stats_health[1,7]))
matrix Stats_health= Stats_health, (Stats_health[1,2] - Stats_health[1,6])
matrix list Stats_health



* Homeland Security and Governmental Affairs
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Homeland Security and Governmental Affairs"
matrix stats_R_homelandsec = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_homelandsec

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Homeland Security and Governmental Affairs"
matrix stats_D_homelandsec = (r(mean), r(sd), r(N))
matrix list stats_D_homelandsec

matrix Stats_homelandsec = stats_R_homelandsec, stats_D_homelandsec
matrix Stats_homelandsec = Stats_homelandsec, (stats_R_homelandsec[1,1] - stats_D_homelandsec[1,1])
matrix Stats_homelandsec = Stats_homelandsec, (Stats_homelandsec[1,8]/sqrt(Stats_homelandsec[1,2]^2/Stats_homelandsec[1,3]+ Stats_homelandsec[1,6]^2/Stats_homelandsec[1,7]))
matrix Stats_homelandsec= Stats_homelandsec, (Stats_homelandsec[1,2] - Stats_homelandsec[1,6])
matrix list Stats_homelandsec




* Judiciary
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Judiciary"
matrix stats_R_Judiciary = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_Judiciary

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Judiciary"
matrix stats_D_Judiciary = (r(mean), r(sd), r(N))
matrix list stats_D_Judiciary

matrix Stats_Judiciary = stats_R_Judiciary, stats_D_Judiciary
matrix Stats_Judiciary = Stats_Judiciary, (stats_R_Judiciary[1,1] - stats_D_Judiciary[1,1])
matrix Stats_Judiciary = Stats_Judiciary, (Stats_Judiciary[1,8]/sqrt(Stats_Judiciary[1,2]^2/Stats_Judiciary[1,3]+ Stats_Judiciary[1,6]^2/Stats_Judiciary[1,7]))
matrix Stats_Judiciary= Stats_Judiciary, (Stats_Judiciary[1,2] - Stats_Judiciary[1,6])
matrix list Stats_Judiciary


* Labor and Human Resources
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Labor and Human Resources"
matrix stats_R_labor = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_labor

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Labor and Human Resources"
matrix stats_D_labor = (r(mean), r(sd), r(N))
matrix list stats_D_labor

matrix Stats_labor = stats_R_labor, stats_D_labor
matrix Stats_labor = Stats_labor, (stats_R_labor[1,1] - stats_D_labor[1,1])
matrix Stats_labor = Stats_labor, (Stats_labor[1,8]/sqrt(Stats_labor[1,2]^2/Stats_labor[1,3]+ Stats_labor[1,6]^2/Stats_labor[1,7]))
matrix Stats_labor= Stats_labor, (Stats_labor[1,2] - Stats_labor[1,6])
matrix list Stats_labor


* Rules and Administration
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Rules and Administration"
matrix stats_R_rules = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_rules

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Rules and Administration"
matrix stats_D_rules = (r(mean), r(sd), r(N))
matrix list stats_D_rules

matrix Stats_rules = stats_R_rules, stats_D_rules
matrix Stats_rules = Stats_rules, (stats_R_rules[1,1] - stats_D_rules[1,1])
matrix Stats_rules = Stats_rules, (Stats_rules[1,8]/sqrt(Stats_rules[1,2]^2/Stats_rules[1,3]+ Stats_rules[1,6]^2/Stats_rules[1,7]))
matrix Stats_rules= Stats_rules, (Stats_rules[1,2] - Stats_rules[1,6])
matrix list Stats_rules


* Small Business and Entrepreneurship
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Small Business and Entrepreneurship"
matrix stats_R_smallbusiness = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_smallbusiness

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Small Business and Entrepreneurship"
matrix stats_D_smallbusiness = (r(mean), r(sd), r(N))
matrix list stats_D_smallbusiness

matrix Stats_smallbusiness = stats_R_smallbusiness, stats_D_smallbusiness
matrix Stats_smallbusiness = Stats_smallbusiness, (stats_R_smallbusiness[1,1] - stats_D_smallbusiness[1,1])
matrix Stats_smallbusiness = Stats_smallbusiness, (Stats_smallbusiness[1,8]/sqrt(Stats_smallbusiness[1,2]^2/Stats_smallbusiness[1,3]+ Stats_smallbusiness[1,6]^2/Stats_smallbusiness[1,7]))
matrix Stats_smallbusiness= Stats_smallbusiness, (Stats_smallbusiness[1,2] - Stats_smallbusiness[1,6])
matrix list Stats_smallbusiness



* Veterans' Affairs
summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Veterans' Affairs"
matrix stats_R_veteranaffair = (r(mean), r(sd), r(N),r(mean)/r(sd))
matrix list stats_R_veteranaffair

summarize chamberseniority if newtocommittee == "1" & party == "D" & committeename == "Veterans' Affairs"
matrix stats_D_veteranaffair = (r(mean), r(sd), r(N))
matrix list stats_D_veteranaffair

matrix Stats_veteranaffair = stats_R_veteranaffair, stats_D_veteranaffair
matrix Stats_veteranaffair = Stats_veteranaffair, (stats_R_veteranaffair[1,1] - stats_D_veteranaffair[1,1])
matrix Stats_veteranaffair = Stats_veteranaffair, (Stats_veteranaffair[1,8]/sqrt(Stats_veteranaffair[1,2]^2/Stats_veteranaffair[1,3]+ Stats_veteranaffair[1,6]^2/Stats_veteranaffair[1,7]))
matrix Stats_veteranaffair= Stats_veteranaffair, (Stats_veteranaffair[1,2] - Stats_veteranaffair[1,6])
matrix list Stats_veteranaffair





** Constructing Table A5:
matrix TableA5 = Stats_smallbusiness \ Stats_veteranaffair \ Stats_Agriculture \ Stats_armedservices \ Stats_energy \ Stats_banking \ Stats_commerce \ Stats_environment \ Stats_Finance \Stats_ForeignRelations \ Stats_GovernmentalAffairs \ Stats_homelandsec \ Stats_Judiciary \ Stats_labor \ Stats_health \ Stats_Appropriations \ Stats_budget \Stats_rules

matrix list TableA5

* Saves TableA5:
esttab matrix(TableA5) using TableA5




** Constructing Table A7 which is the mean, standard deviation and mean/standard deviation of Republican Chamber seniority at time of appointment

* Note: Govt Affairs and Homeland Security were combined in the midst of this data:
matrix GovtAffairs_mean = (stats_R_GovernmentalAffairs[1,1]*stats_R_GovernmentalAffairs[1,3] + stats_R_homelandsec[1,1]*stats_R_homelandsec[1,3])/(stats_R_GovernmentalAffairs[1,3]+stats_R_homelandsec[1,3])
matrix GovtAffairs_stddev = (stats_R_GovernmentalAffairs[1,2]*stats_R_GovernmentalAffairs[1,3] + stats_R_homelandsec[1,2]*stats_R_homelandsec[1,3])/(stats_R_GovernmentalAffairs[1,3]+stats_R_homelandsec[1,3])
matrix GovtAffairs_N = stats_R_GovernmentalAffairs[1,3]+stats_R_homelandsec[1,3]
matrix GovtAffairs_stdmean = GovtAffairs_mean[1,1]/GovtAffairs_stddev[1,1]

matrix Stats_GovtAffairs = GovtAffairs_mean, GovtAffairs_stddev, GovtAffairs_N, GovtAffairs_stdmean

matrix list Stats_GovtAffairs

* Note: Labor and Human Resources became Health, Education, Labor, and Pensions
matrix LaborHumanRes_mean = (Stats_labor[1,1]*Stats_labor[1,3] + Stats_health[1,1]*Stats_health[1,3])/(Stats_labor[1,3]+Stats_health[1,3])
matrix LaborHumanRes_stddev = (Stats_labor[1,2]*Stats_labor[1,3] + Stats_health[1,2]*Stats_health[1,3])/(Stats_labor[1,3]+Stats_health[1,3])
matrix LaborHumanRes_N = Stats_labor[1,3]+Stats_health[1,3]
matrix LaborHumanRes_stdmean = LaborHumanRes_mean[1,1]/LaborHumanRes_stddev[1,1]

matrix Stats_LaborHumanRes = LaborHumanRes_mean, LaborHumanRes_stddev, LaborHumanRes_N, LaborHumanRes_stdmean

matrix list Stats_LaborHumanRes




** Constructing Table A7 which is the mean, standard deviation and mean/standard deviation of Republican Chamber seniority at time of appointment
matrix TableA7Column1 = stats_R_commerce[1,1] \ stats_R_armedservices[1,1] \ stats_R_smallbusiness[1,1] \ stats_R_veteranaffair[1,1] \ stats_R_ForeignRelations[1,1] \ stats_R_Agriculture[1,1] \ stats_R_banking[1,1] \ stats_R_energy[1,1] \ stats_R_budget[1,1]  \ stats_R_environment[1,1] \ stats_R_Judiciary[1,1] \stats_R_Appropriations[1,1] \ Stats_GovtAffairs[1,1] \ Stats_LaborHumanRes[1,1] \ stats_R_rules[1,1] \stats_R_Finance[1,1] 

matrix list TableA7Column1
 

 matrix TableA7Column2 = stats_R_armedservices[1,2] \ stats_R_commerce[1,2] \ stats_R_veteranaffair[1,2] \ stats_R_smallbusiness[1,2] \ stats_R_Appropriations[1,2] \ stats_R_budget[1,2]  \ stats_R_Agriculture[1,2] \ stats_R_Finance[1,2] \ stats_R_ForeignRelations[1,2] \ stats_R_banking[1,2] \ stats_R_energy[1,2] \ stats_R_Judiciary[1,2] \ stats_R_environment[1,2] \ stats_R_rules[1,2] \ Stats_LaborHumanRes[1,2] \ Stats_GovtAffairs[1,2]

 matrix list TableA7Column2


matrix TableA7Column3 = stats_R_ForeignRelations[1,4] \ stats_R_smallbusiness[1,4] \ stats_R_energy[1,4] \ stats_R_banking[1,4] \ stats_R_environment[1,4] \ stats_R_Judiciary[1,4] \ stats_R_Agriculture[1,4] \ Stats_GovtAffairs[1,4] \ stats_R_veteranaffair[1,4] \ Stats_LaborHumanRes[1,4] \ stats_R_budget[1,4]  \ stats_R_rules[1,4] \ stats_R_commerce[1,4] \ stats_R_Appropriations[1,4] \ stats_R_armedservices[1,4] \ stats_R_Finance[1,4] 

matrix list TableA7Column3

* Saves TableA7 by Columns:
esttab matrix(TableA7Column1) using TableA7Column1
esttab matrix(TableA7Column2) using TableA7Column2
esttab matrix(TableA7Column3) using TableA7Column3


*************************************************************************************
** Table A8**
*************************************************************************************

recast byte congress 

* First collect the minimum seniority at time of committee assignment for each congress 104-113 for every committee
matrix Rmin_Agriculture = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Agriculture, Nutrition, and Forestry" & congress == `j'
matrix Rmin_Agriculture = Rmin_Agriculture,(r(min))
}
matrix Rmin_Agriculture = Rmin_Agriculture[1,2..11]


matrix Rmin_Appropriations = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Appropriations" & congress == `j'
matrix Rmin_Appropriations = Rmin_Appropriations,(r(min))
}
matrix Rmin_Appropriations = Rmin_Appropriations[1,2..11]


matrix Rmin_ArmedService = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Armed Services" & congress == `j'
matrix Rmin_ArmedService = Rmin_ArmedService,(r(min))
}
matrix Rmin_ArmedService = Rmin_ArmedService[1,2..11]


matrix Rmin_Banking = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Banking, Housing, and Urban Affairs" & congress == `j'
matrix Rmin_Banking = Rmin_Banking,(r(min))
}
matrix Rmin_Banking = Rmin_Banking[1,2..11]


matrix Rmin_Budget = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Budget" & congress == `j'
matrix Rmin_Budget = Rmin_Budget,(r(min))
}
matrix Rmin_Budget = Rmin_Budget[1,2..11]


matrix Rmin_Commerce = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Commerce, Science, and Transportation" & congress == `j'
matrix Rmin_Commerce = Rmin_Commerce,(r(min))
}
matrix Rmin_Commerce = Rmin_Commerce[1,2..11]


matrix Rmin_Energy = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Energy and Natural Resources" & congress == `j'
matrix Rmin_Energy = Rmin_Energy,(r(min))
}
matrix Rmin_Energy = Rmin_Energy[1,2..11]


matrix Rmin_Environment = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Environment and Public Works" & congress == `j'
matrix Rmin_Environment = Rmin_Environment,(r(min))
}
matrix Rmin_Environment = Rmin_Environment[1,2..11]


matrix Rmin_Finance = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Finance" & congress == `j'
matrix Rmin_Finance = Rmin_Finance,(r(min))
}
matrix Rmin_Finance = Rmin_Finance[1,2..11]


matrix Rmin_ForeignRelations = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Foreign Relations" & congress == `j'
matrix Rmin_ForeignRelations = Rmin_ForeignRelations,(r(min))
}
matrix Rmin_ForeignRelations = Rmin_ForeignRelations[1,2..11]


matrix Rmin_GovernmentAffairs = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Governmental Affairs" & congress == `j'
matrix Rmin_GovernmentAffairs = Rmin_GovernmentAffairs,(r(min))
}
matrix Rmin_GovernmentAffairs = Rmin_GovernmentAffairs[1,2..11]


matrix Rmin_HomelandSec = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Homeland Security and Governmental Affairs" & congress == `j'
matrix Rmin_HomelandSec = Rmin_HomelandSec,(r(min))
}
matrix Rmin_HomelandSec = Rmin_HomelandSec[1,2..11]

* Note: Govt Affairs and Homeland Security names were swtiched, so we combine
matrix Rmin_GovernmentalAffairs = (Rmin_GovernmentAffairs[1,1..5], Rmin_HomelandSec[1,6..10])


matrix Rmin_Labor = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Labor and Human Resources" & congress == `j'
matrix Rmin_Labor = Rmin_Labor,(r(min))
}
matrix Rmin_Labor = Rmin_Labor[1,2..11]


matrix Rmin_Health = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Health, Education, Labor, and Pensions" & congress == `j'
matrix Rmin_Health = Rmin_Health,(r(min))
}
matrix Rmin_Health = Rmin_Health[1,2..11]

*Note: Labor and Human Resources became Health, Education, Labor, and Pensions, so we combine
matrix Rmin_LaborHumanResources = (Rmin_Labor[1,1..3], Rmin_Health[1,4..10])


matrix Rmin_Judiciary = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Judiciary" & congress == `j'
matrix Rmin_Judiciary = Rmin_Judiciary,(r(min))
}
matrix Rmin_Judiciary = Rmin_Judiciary[1,2..11]


matrix Rmin_Rules = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Rules and Administration" & congress == `j'
matrix Rmin_Rules = Rmin_Rules,(r(min))
}
matrix Rmin_Rules = Rmin_Rules[1,2..11]


matrix Rmin_SmallBusiness = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Small Business and Entrepreneurship" & congress == `j'
matrix Rmin_SmallBusiness = Rmin_SmallBusiness,(r(min))
}
matrix Rmin_SmallBusiness = Rmin_SmallBusiness[1,2..11]


matrix Rmin_VeteransAffairs = 0
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & committeename == "Veterans' Affairs" & congress == `j'
matrix Rmin_VeteransAffairs = Rmin_VeteransAffairs,(r(min))
}
matrix Rmin_VeteransAffairs = Rmin_VeteransAffairs[1,2..11]


matrix A = Rmin_ForeignRelations \ Rmin_SmallBusiness \ Rmin_Banking \ Rmin_Commerce \ Rmin_ArmedService \ Rmin_Energy \Rmin_Agriculture \ Rmin_VeteransAffairs \ Rmin_Environment \ Rmin_GovernmentalAffairs \Rmin_Budget \ Rmin_Judiciary \Rmin_Rules \ Rmin_LaborHumanResources \Rmin_Appropriations \Rmin_Finance
matrix list A


// Step 2: Create a new dataset with the same number of observations as columns in the matrix
clear
set obs `=colsof(A)'  // Create one observation for each column in the matrix

// Step 3: Create variables for each row of the matrix
forval i = 1/`=rowsof(A)' {
    gen row`i' = .
    // Step 4: Assign the values of each row from the matrix to the new variable
    forval j = 1/`=colsof(A)' {
        replace row`i' = A[`i', `j'] in `j'
    }
}

// Display the dataset with the new variables
list


* Now we can compute the mean of min, std deviation of min, and mean/standard deviation of min for each committee

matrix StatsMinChambSen = [0,0,0]

forval i = 1/`=rowsof(A)' {
    summarize row`i'
matrix StatsMinChambSen = StatsMinChambSen \ (r(mean), r(sd), r(mean)/r(sd))
}

* These three, when sorted are the three columns of Table A8.
matrix TableA8 = StatsMinChambSen[2..17,.] 

matrix list TableA8

* Saves TableA8:
esttab matrix(TableA8) using TableA8


*************************************************************************************
** Table A6 **
*************************************************************************************

 clear
// Download the Senate Committee Assignments data
 use SenateChamberSeniorityAtAssignment.dta


* First let's calculate the average Republican Seniority on each committee by Congress: for all members, excluding senior most, excluding two senior most, and excluding three senior most members

*Agriculture
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Agriculture, Nutrition, and Forestry"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Agriculture, Nutrition, and Forestry" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Agriculture, Nutrition, and Forestry" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Agriculture, Nutrition, and Forestry" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_Agriculture  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_Agriculture


*ArmedServices
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Armed Services"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Armed Services" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Armed Services" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Armed Services" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_ArmedServices  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_ArmedServices


*Appropriations
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Appropriations"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Appropriations" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Appropriations" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Appropriations" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_Appropriations  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_Appropriations


*Banking
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Banking, Housing, and Urban Affairs"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Banking, Housing, and Urban Affairs" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Banking, Housing, and Urban Affairs" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Banking, Housing, and Urban Affairs" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_Banking  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_Banking


*Budget
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Budget"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Budget" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Budget" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Budget" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_Budget  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_Budget

*Commerce
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Commerce, Science, and Transportation"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Commerce, Science, and Transportation" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Commerce, Science, and Transportation" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Commerce, Science, and Transportation" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_Commerce  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_Commerce

*Energy
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Energy and Natural Resources"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Energy and Natural Resources" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Energy and Natural Resources" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Energy and Natural Resources" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_Energy  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_Energy


*Environment
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Environment and Public Works"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Environment and Public Works" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Environment and Public Works" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Environment and Public Works" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_Environment  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_Environment

*Finance
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Finance"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Finance" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Finance" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Finance" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_Finance  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_Finance

*ForeignRelations
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Foreign Relations"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Foreign Relations" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Foreign Relations" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Foreign Relations" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_ForeignRelations  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_ForeignRelations

*GovtAffairs -- note this committee exists only in congresses 103 to 108
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/108 { 
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Governmental Affairs"
	matrix All = All[1,1] + [r(mean)/6]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Governmental Affairs" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/6]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Governmental Affairs" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/6]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Governmental Affairs" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/6]
}
matrix Sen_GovtAffairs  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_GovtAffairs


*Health  -- note this committee exists only in congresses 107 to 113 congresses
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 107/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Health, Education, Labor, and Pensions"
	matrix All = All[1,1] + [r(mean)/7]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Health, Education, Labor, and Pensions" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/7]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Health, Education, Labor, and Pensions" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/7]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Health, Education, Labor, and Pensions" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/7]
}
matrix Sen_Health  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_Health

*HomelandSec  -- note this committee exists only in congresses 109 to 113 congresses
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 109/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Homeland Security and Governmental Affairs"
	matrix All = All[1,1] + [r(mean)/5]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Homeland Security and Governmental Affairs" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/5]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Homeland Security and Governmental Affairs" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/5]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Homeland Security and Governmental Affairs" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/5]
}
matrix Sen_HomelandSec  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_HomelandSec

*Judiciary
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Judiciary"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Judiciary" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Judiciary" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Judiciary" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_Judiciary  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_Judiciary

*Labor  -- note this committee exists only in congresses 103 to 106 congresses
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/106 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Labor and Human Resources"
	matrix All = All[1,1] + [r(mean)/4]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Labor and Human Resources" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/4]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Labor and Human Resources" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/4]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Labor and Human Resources" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/4]
}
matrix Sen_Labor  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_Labor

*Rules
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Rules and Administration"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Rules and Administration" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Rules and Administration" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Rules and Administration" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_Rules  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_Rules


*SmallBusiness
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Small Business and Entrepreneurship"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Small Business and Entrepreneurship" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Small Business and Entrepreneurship" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Small Business and Entrepreneurship" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_SmallBusiness  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_SmallBusiness

*VeteransAffairs
matrix All=0
matrix All_exclu1senior=0
matrix All_exclu2senior=0
matrix All_exclu3senior=0
forval j = 103/113 {
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Veterans' Affairs"
	matrix All = All[1,1] + [r(mean)/11]

	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Veterans' Affairs" & rank > 1
	matrix All_exclu1senior = All_exclu1senior[1,1] + [r(mean)/11]
	
		summarize chamberseniority if party == "R" & congress == `j' & committeename == "Veterans' Affairs" & rank > 2
	matrix All_exclu2senior = All_exclu2senior[1,1] + [r(mean)/11]
	
	summarize chamberseniority if party == "R" & congress == `j' & committeename == "Veterans' Affairs" & rank > 3
	matrix All_exclu3senior = All_exclu3senior[1,1] + [r(mean)/11]
}
matrix Sen_VeteransAffairs  = All \ All_exclu1senior \ All_exclu2senior \ All_exclu3senior

matrix list Sen_VeteransAffairs




matrix TableA6Column1 = Sen_SmallBusiness[1,1] \ Sen_ForeignRelations[1,1] \ Sen_Labor[1,1] \ Sen_Banking[1,1] \ Sen_Commerce[1,1] \ Sen_ArmedServices[1,1] \ Sen_Energy[1,1] \ Sen_Environment[1,1] \ Sen_Health[1,1] \ Sen_Budget[1,1] \ Sen_VeteransAffairs[1,1] \ Sen_HomelandSec[1,1] \ Sen_Agriculture[1,1] \ Sen_Judiciary[1,1] \Sen_GovtAffairs[1,1] \ Sen_Appropriations[1,1] \Sen_Finance[1,1] \Sen_Rules[1,1]

matrix list TableA6Column1


matrix TableA6Column2 = Sen_ForeignRelations[2,1] \ Sen_SmallBusiness[2,1] \ Sen_Banking[2,1] \ Sen_Labor[2,1]  \ Sen_ArmedServices[2,1] \ Sen_Commerce[2,1] \ Sen_Energy[2,1] \ Sen_Environment[2,1] \  Sen_Budget[2,1] \Sen_Health[2,1] \ Sen_VeteransAffairs[2,1] \ Sen_HomelandSec[2,1] \ Sen_Judiciary[2,1] \Sen_Agriculture[2,1] \  Sen_Appropriations[2,1] \Sen_Finance[2,1] \Sen_GovtAffairs[2,1] \Sen_Rules[2,1]

matrix list TableA6Column2


matrix TableA6Column3 = Sen_SmallBusiness[3,1] \ Sen_ForeignRelations[3,1] \  Sen_Banking[3,1] \ Sen_ArmedServices[3,1] \ Sen_Commerce[3,1] \ Sen_Energy[3,1] \ Sen_Labor[3,1]  \ Sen_Environment[3,1] \  Sen_Budget[3,1]  \ Sen_Judiciary[3,1] \Sen_VeteransAffairs[3,1] \Sen_Health[3,1] \ Sen_HomelandSec[3,1] \ Sen_Agriculture[3,1] \  Sen_Appropriations[3,1] \Sen_Finance[3,1] \Sen_GovtAffairs[3,1] \Sen_Rules[3,1]

matrix list TableA6Column3

matrix TableA6Column4 = Sen_SmallBusiness[4,1] \ Sen_ForeignRelations[4,1] \  Sen_ArmedServices[4,1] \ Sen_Banking[4,1] \ Sen_Commerce[4,1] \  Sen_Energy[4,1] \ Sen_Budget[4,1]   \ Sen_Environment[4,1] \   Sen_VeteransAffairs[4,1] \Sen_Judiciary[4,1] \Sen_Labor[4,1] \Sen_Agriculture[4,1] \ Sen_Health[4,1] \ Sen_HomelandSec[4,1] \  Sen_Appropriations[4,1] \Sen_GovtAffairs[4,1] \ Sen_Finance[4,1] \Sen_Rules[4,1]

matrix list TableA6Column4

* Saves Table 6 by columns
esttab matrix(TableA6Column1) using TableA6Column1
esttab matrix(TableA6Column2) using TableA6Column2
esttab matrix(TableA6Column3) using TableA6Column3
esttab matrix(TableA6Column4) using TableA6Column4




*************************************************************************************
** Figure C1 **
*************************************************************************************



clear
// Download the Senate Committee Assignments data
use SenateChamberSeniorityAtAssignment.dta

* First let's calculate the number of new assignments by party by Congress for non-freshmen; and the number of committee assignments of non-freshmen by party by Congress
matrix NumNonfreshmenNewAssignments= [0,0]
forval j = 104/113 {
	summarize chamberseniority if newtocommittee == "1" & party == "R" & congress == `j' & chamberseniority > 1
	matrix Rcount_new = r(N)

	summarize chamberseniority if newtocommittee == "1" & party == "D" & congress == `j' & chamberseniority > 1
	matrix Dcount_new = r(N)
	
		summarize chamberseniority if party == "R" & congress == `j' & chamberseniority > 1
	matrix Rcount_total = r(N)

	summarize chamberseniority if party == "D" & congress == `j' & chamberseniority > 1
	matrix Dcount_total = r(N)
	
	* Percentage new assignments:
	matrix PercentageNewCommittee_Dem = Dcount_new[1,1] / Dcount_total[1,1]
	matrix PercentageNewCommittee_Rep = Rcount_new[1,1] / Rcount_total[1,1]
	
	matrix Counts = PercentageNewCommittee_Dem, PercentageNewCommittee_Rep

	matrix NumNonfreshmenNewAssignments = NumNonfreshmenNewAssignments \ Counts
}
matrix NumNonfreshmenNewAssignments = NumNonfreshmenNewAssignments[2..11,.]



** Figure C1 ** 
* is made by graphing these Democrat percentage new assignments in Column 1 by Congress next to these Republican percentage new assignments in Column 2 by Congress.
matrix list NumNonfreshmenNewAssignments

* Saves Figure C1 data
esttab matrix(NumNonfreshmenNewAssignments) using FigureC1Data

